//========================================================================
/**
*  Copyright (c), 2007-2009.
*  @file	cx_list.h
*  @author	godwinguo
*  @email	godwinguo@tencent.com
*  @brief	Red-black search tree
*  @version	1.0.0
*  @history
*    <author>      <time>      <version>     <desc>
*  ------------ ------------  ------------  -----------------
*    godwinguo   2010/01/19     1.0.0        Copy from BaseStruct
*/
//========================================================================

#ifndef __CX_HASHTAB_H__ 
#define __CX_HASHTAB_H__

/*************************************************************************
* MACRO
*************************************************************************/

#if defined(__CC_ARM)
#define __ALIGN( __x )	__align(4)
#else	// #if defined(__CC_ARM)
#define __ALIGN( __x )
#endif	// #if defined(__CC_ARM)

#define __FAR_PROC	*

/*************************************************************************
* PROTOTYPE
*************************************************************************/

struct __struct_hash_table;
typedef struct __struct_hash_table		hash_table_t;
typedef struct __struct_hash_table *	hash_table_ptr_t;

/*************************************************************************
* STRUCTURE
*************************************************************************/

__ALIGN(4) struct __struct_hash_table
{
	unsigned long	size;
	signed long		( __FAR_PROC cmp )( const void * x, const void * y );
	unsigned long	( __FAR_PROC hash )( const void * key );
	unsigned long	length;
	unsigned long	timestamp;
	struct binding
	{
		struct binding *	link;
		const void *		key;
		void *				value;
	} ** buckets;
};

hash_table_ptr_t	cx_ht_New ( unsigned long hint, signed long cmp(const void *x, const void *y), unsigned long hash(const void *key));
void				cx_ht_Release( hash_table_ptr_t table );
unsigned long		cx_ht_length( hash_table_ptr_t table );
void *				cx_ht_put( hash_table_ptr_t table, const void * key, void * value );
void *				cx_ht_get( hash_table_ptr_t table, const void * key );
void *				cx_ht_remove( hash_table_ptr_t table, const void * key );
void				cx_ht_map( hash_table_ptr_t table, void apply(const void *key, void **value, void *cl), void *cl);
void **				cx_ht_toArray( hash_table_ptr_t table, void * end );

#endif	// #ifndef __CX_HASHTAB_H__ 
